﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace f1
{
    public partial class Form_update : Form
    {
        int num;
        String new_product;
        String new_customer;
        double new_price;
        public Form_update()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void tb_num_TextChanged(object sender, EventArgs e)
        {
            this.num = Convert.ToInt32(tb_num.Text);
            var allOrders = from item in OrderService.orderList where item != null && item.getOrderNum() == num select item;
            foreach (var item in allOrders)
            {
                tb_product.Text = item.getProduct();
                tb_customer.Text = item.getCustomer();
                tb_price.Text =Convert.ToString( item.getPrice());
            }
        }

        private void tb_product_TextChanged(object sender, EventArgs e)
        {
            this.new_product = tb_product.Text;
        }

        private void tb_customer_TextChanged(object sender, EventArgs e)
        {
            this.new_customer = tb_customer.Text;
        }

        private void tb_price_TextChanged(object sender, EventArgs e)
        {
            this.new_price = Convert.ToDouble(tb_price.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (OrderService.updateOrder(num, new_product, new_customer, new_price))
                {
                    DialogResult result = MessageBox.Show("更改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
                else
                {
                    DialogResult result = MessageBox.Show("更改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch
            {
                DialogResult result = MessageBox.Show("更改失败2", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
